package edu.udel.mboch.towerdefense;

import java.util.ArrayList;

public class BasicTower extends Tower
{
	private static final long serialVersionUID = 475394244453392223L;

	public BasicTower(Position position)
	{
		super(position, 3);
		damage = 8;
		speed = 1000;
		range = 3;
		cost = Tower.BASIC_COST;
		name = "Basic Tower";
		timer = speed;
	}
	
	public BasicTower(Position position, ArrayList<Position> positionsInRange)
	{
		super(position, positionsInRange, 3);
		damage = 10;
		speed = 1000;
		range = 3;
		cost = Tower.BASIC_COST;
		name = "Basic Tower";
	}
	
	public void shoot(TDState state)
	{
		if(timer>speed)
		{
			ArrayList<Mob> mobs = getMobsInRange(state);
			int min = Integer.MAX_VALUE;
			int minLoc = -1;
			if(mobs.size()>0)
			{
				for(int i = 0; i<mobs.size(); i++)
					if(mobs.get(i).getDistanceToEnd() < min)
					{
						min = mobs.get(i).getDistanceToEnd();
						minLoc = i;
					}
				state.getGrid().addProjectile(new Projectile(this, mobs.get(minLoc)));
			}
			if(mobs.size() > 0)
				while(timer>speed)
					timer%=speed;
		}
	}
	
	public BasicTower copy()
	{
		return new BasicTower(position.copy(), positionsInRange);
	}
	
	public void print()
	{
		System.out.print('T');
	}
}
